<?php
class CheckController extends Controller {

	/**
	 * 相册作者权限检查
	 * 
	 * @param int $id        	
	 */
	public function actionIndex ($id) {
		$aid = (int) $id;
		if ($this->module->checkIdentity($aid, 'author'))
			$this->showError('进错页面了吧?');
		
		$model = 'Album';
		if (!($album = CActiveRecord::model($model)->findByPk($aid)))
			$this->showError('抱歉.没有找到相册!');
		
		$questionModel = 'AlbumQuestion';
		$albumAuthorQuestion = $album->questionAuthor;
		$question = new $questionModel();
		$question->question = $albumAuthorQuestion->question;
		if (isset($_POST[$questionModel])) {
			$question->attributes = $_POST[$questionModel];
			if ($question->validateQuestion($albumAuthorQuestion)) {
				// 标识权限
				$this->module->setIdentity($aid, 'author');
				$this->redirect(Yii::app()->request->getUrlReferrer());
			}
		}
		$this->render('index', array(
			'album' => $album,
			'question' => $question 
		));
	}
}
?>